 #include "Task/TaskMng.h"
#include "Algorithm/Algorithm.h"
#include "Scheduler/Proxy.h"
#include <stdio.h>
#include <iostream>
#include <pthread.h>
#include <process.h>
#include <sys/trace.h>
#include "Algorithm/RM.h"
#include "Algorithm/EDF.h"
#include "Algorithm/SCT.h"
#include "Analyzer/Analyzer.h"
#include <unistd.h>

Scheduler *selectAlgr();
bool finishAll=false;

int main(int argc, char *argv[]) {

	TaskMng tMngr;
	Scale scale;
	Scheduler *schd;
	Analyzer analyzer;

	// set name for main thread
	pthread_setname_np(pthread_self(), "main");

	// getting all tasks
	tMngr.loadTask(&scale);

	// select Algorithm
	schd= selectAlgr();

	// setup the scheduler and execute  (run) the tasks
	schd->setup(&scale,&tMngr);
	schd->execute();

	sleep(6);
	analyzer.print(tMngr);
}


Scheduler *selectAlgr() {

	Scheduler *sch;
	int algrNumIn;

	cout << "Please select algorithm type:\n 1) Rate Monotonic.\n 2) Earliest Deadline First.\n 3) Shortest Completion Time.\n\n(Please enter the number beside algorithm name.)\n\nYour selection is: ";
	cin >> algrNumIn;

	switch (algrNumIn) {
	case 1:
		sch= new Scheduler();
		sch->algr= new RM();
		return sch;
		break;
	case 2:
		sch= new Scheduler();
		sch->algr= new EDF();
		return sch;
		break;
	case 3:
		sch= new Scheduler();
		sch->algr= new SCT();
		return sch;
		break;
	default:
		sch= new Scheduler();
		sch->algr= new RM();
		return sch;
		break;
	}
}
